<template>
  <div class="container flow-column h100">
    <div class="container-main h100">
      <list-table-new v-bind="tableSetting" ref="klTable"></list-table-new>
    </div>
  </div>
</template>
<script>
/**
 * 用于选择评级标准的关联页面
 * searchData:{
 *   typeId: 关联台账的设备分类id
 *   typeName: 关联台账的设备分类名称
 * }
 */
import { queryRatingList } from "@/api/standardManagement/ratingStandard.js";
export default {
  props: {
    searchData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    //已选的id
    selectId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      tableSetting: {
        radioShow: true,
        showFilterBtn: false,
        showCustomBtn: false,
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15,
            status: "1",
            publicStatus: 1,
          },
          searchArr: [
            {
              type: "input",
              label: "标题",
              model: "name",
              placeholder: "请输入",
            },
            {
              type: "deviceClassify",
              label: "设备分类",
              model: "typeName",
              idsStr: "typeId",
              // disabled: true,
            },
            {
              type: "select",
              label: "状态",
              model: "status",
              disabled: true,
              option: [
                {
                  value: "0",
                  label: "草稿",
                },
                {
                  value: "1",
                  label: "已发布",
                },
              ],
            },
          ],
        },
        column: [
          {
            label: "编号",
            prop: "code",
            sortable: "custom",
          },
          {
            label: "标题",
            prop: "name",
            sortable: "custom",
          },
          {
            label: "设备分类",
            prop: "typeName",
            sortable: "custom",
          },
          {
            label: "状态",
            prop: "status",
            sortable: "custom",
            formatter: (row) => {
              return row.status == 0 ? "草稿" : "已发布";
            },
          },
          {
            label: "适用范围",
            prop: "appName",
            sortable: "custom",
          },
          {
            label: "创建单位",
            prop: "deptName",
            sortable: "custom",
          },
          {
            label: "创建人",
            prop: "createByName",
            sortable: "custom",
          },
          {
            label: "创建时间",
            prop: "createTime",
            sortable: "custom",
          },
        ],
        //表格方法
        tableMethods: {
          //点击行的方法
          rowClick: (row) => {
            this.$refs.klTable.radioSelect(row);
          },
        },
      },
    };
  },
  created() {
    this.tableSetting.searchObj.queryData = Object.assign(
      this.tableSetting.searchObj.queryData,
      this.searchData
    );
  },
  mounted() {
    this.updateData();
  },
  methods: {
    //更新列表页的数据
    updateData() {
      this.$refs.klTable.searchData();
    },
    // 获取表格数据
    getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      if (sortStr.length > 0) {
        queryData.orders = sortStr;
      }
      queryData.appid = this.$store.getters.currentAppInfo.appId;
      queryRatingList(queryData).then((res) => {
        this.$set(this.tableSetting, "tableData", res.data.records);
        this.$set(this.tableSetting, "totalNumber", res.data.total);
        this.$refs.klTable.radioSelect({ id: this.selectId });
      });
    },
    //获取选中数据
    getselectData() {
      let data = this.$refs.klTable.getRadioData();
      return data;
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  .container-main {
    /deep/ .list-table-search,
    /deep/ .table-search--action,
    /deep/ .kr-list-table-box .kr-table-pagination,
    /deep/ .el-pagination {
      background-color: #fff;
    }
    /deep/.search--btnOverflow {
      margin-bottom: 0;
    }
  }
}
.flow-column {
  display: flex;
  flex-flow: column nowrap;
}
</style>